//
// Created by Leaf on 2025/8/17.
//

#include "my_rtosConfig.h"
#include <freertos/timers.h>
#include "global/GData.h"
#include "net/ESP_NOW.h"

// 定时器ID定义
#define HEARTBEAT_TIMER_ID 1

uint32_t timeCount = 0;


// 定时器回调函数声明
void oneDayTimerCallback(TimerHandle_t xTimer){
    if(timeCount >= one_day_ticks){
        visitors_today = 0; // 每日访问次数归零
        timeCount = 0;
        printf("Today's visitors have been cleared\n");
    }
//    else{
//        printf("Today's visitors: %d\n", visitors_today);
//    }
    timeCount ++;
};


// 定时器初始化
void Timer_init(){
    // 定时器句柄 (参数：定时器名称，定时时间，自动重载，定时器ID，定时器回调函数)
    TimerHandle_t xHeartbeatTimer = xTimerCreate(
        "OneDayTimer", 
        pdMS_TO_TICKS(1000),
        pdTRUE, 
        (void *)HEARTBEAT_TIMER_ID, 
        oneDayTimerCallback
    );
    xTimerStart(xHeartbeatTimer, 0);    // 启动定时器 参数：定时器句柄，阻塞时间
}